package com.ruoyi.mysystem.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mysystem.domain.SysCollectionList;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mysystem.domain.SysCollection;
import com.ruoyi.mysystem.service.ISysCollectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收藏管理Controller
 * 
 * @author bai
 * @date 2024-02-06
 */
@RestController
@RequestMapping("/mysystem/collection")
public class SysCollectionController extends BaseController
{
    @Autowired
    private ISysCollectionService sysCollectionService;

    /**
     * 查询收藏管理列表
     */
    @PreAuthorize("@ss.hasPermi('mysystem:collection:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCollection sysCollection)
    {
        startPage();
        List<SysCollection> list = sysCollectionService.selectSysCollectionList(sysCollection);
        return getDataTable(list);
    }

    /**
     * 导出收藏管理列表
     */
    @PreAuthorize("@ss.hasPermi('mysystem:collection:export')")
    @Log(title = "收藏管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCollection sysCollection)
    {
        List<SysCollection> list = sysCollectionService.selectSysCollectionList(sysCollection);
        ExcelUtil<SysCollection> util = new ExcelUtil<SysCollection>(SysCollection.class);
        util.exportExcel(response, list, "收藏管理数据");
    }

    /**
     * 获取收藏管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mysystem:collection:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(sysCollectionService.selectSysCollectionByUserId(userId));
    }

    /**
     * 新增收藏管理
     */
    @PreAuthorize("@ss.hasPermi('mysystem:collection:add')")
    @Log(title = "收藏管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCollection sysCollection)
    {
        return toAjax(sysCollectionService.insertSysCollection(sysCollection));
    }

    /**
     * 取消收藏管理
     */
    @PreAuthorize("@ss.hasPermi('mysystem:collection:remove')")
    @Log(title = "收藏管理", businessType = BusinessType.DELETE)
    @PostMapping("/cancel")
    public AjaxResult cancelCollection(@RequestBody SysCollection cancelCollection)
    {
        return toAjax(sysCollectionService.cancelCollection(cancelCollection));
    }
    /**
     * 批量取消收藏管理
     */
    @PreAuthorize("@ss.hasPermi('mysystem:collection:remove')")
    @Log(title = "收藏管理", businessType = BusinessType.DELETE)
    @PostMapping("/cancelList")
    public AjaxResult cancelCollectionList(@RequestBody SysCollectionList sysCollectionList)
    {
        return toAjax(sysCollectionService.cancelCollectionList(sysCollectionList));
    }

    /**
     * 修改收藏管理
     */
    @PreAuthorize("@ss.hasPermi('mysystem:collection:edit')")
    @Log(title = "收藏管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCollection sysCollection)
    {
        return toAjax(sysCollectionService.updateSysCollection(sysCollection));
    }

    /**
     * 删除收藏管理
     */
    @PreAuthorize("@ss.hasPermi('mysystem:collection:remove')")
    @Log(title = "收藏管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(sysCollectionService.deleteSysCollectionByUserIds(userIds));
    }
}
